<?php
namespace app\admin\controller;
use think\Controller;
use think\Db;
use think\Request;
use think\Cache;

use app\admin\model\ComValidate;
use app\admin\model\ComModel;

class Index extends Common {
	
	public function index(){

		if(request()->isget()){

			$this->assign('title',"站点设置");
			$info=Db::name('site_list')->order('siteid desc')->find();
			$this->assign('info',$info);
			return $this->fetch();

		}else{

			$this->log("修改站点信息");

			$data=input('post.');

			ComValidate::Site_Validate($data);
			
			unset($data['file']);

			if($data['siteid']){
				
				ComModel::data_up('site_list',$data);

			}else{
				
				ComModel::data_add('site_list',$data);

			}
			

		}
		
	}

	#清空缓存#
	public function delcache(){

		$this->log("清除缓存");

		Cache::clear();  

		$this->success("缓存清除成功~");
	}

	#服务器信息#
	public function serverinfo(){

		$this->log("查看服务器信息");
		$this->assign('title',"服务器信息");

		$config=config("database");

		mysql_connect($config['hostname'], $config['username'], $config['password']);
		$info = array(
			'操作系统'=>PHP_OS,
			'运行环境'=>$_SERVER["SERVER_SOFTWARE"],
			'PHP服务器版本'=>PHP_VERSION,
			'Mysql版本'=>mysql_get_server_info(),
			'PHP运行方式'=>php_sapi_name(),
			'ThinkPHP版本'=>THINK_VERSION,
			'上传附件限制'=>ini_get('upload_max_filesize'),
			'执行时间限制'=>ini_get('max_execution_time').'秒',
			'服务器时间'=>date("Y年n月j日 H:i:s"),
			'北京时间'=>gmdate("Y年n月j日 H:i:s",time()+8*3600),
			'服务器域名/IP'=>$_SERVER['SERVER_NAME'].' [ '.gethostbyname($_SERVER['SERVER_NAME']).' ]',
			'剩余空间'=>function_exists(disk_free_space)?round((disk_free_space(".")/(1024*1024)),2).'M':'未知',
			'register_globals'=>get_cfg_var("register_globals")=="1" ? "ON" : "OFF",
			'magic_quotes_gpc'=>(1===get_magic_quotes_gpc())?'YES':'NO',
			'magic_quotes_runtime'=>(1===get_magic_quotes_runtime())?'YES':'NO',

		);

		$this->assign('info',$info);

		return $this->fetch();

	}

	


}